"""
pre-commit hook for thehat project
to use it, put to thehat/.git/hooks/

On Linux or Mac, file named 'pre-commit' with content:
    #!/bin/sh
    python pre-commit.py
Make sure you have right of executing this file

On Windows, file named 'pre-comit.bat' with content:
    python pre-commit.py
"""
from sys import exit
from os import system, devnull
system('git stash -q --keep-index')
print 'Running tests'
exitcode = 0
if system('ant test > {}'.format(devnull)) > 0:
    print 'Error! Some tests fail'
    exitcode = 57
else:
    print 'OK'
    print 'Checking PEP8'
    if system('ant pep8 > {}'.format(devnull)) > 0:
        print 'Error! PEP8 violation'
        exitcode = 57
    else:
        print 'OK'
system('git stash pop -q')
exit(exitcode)
